package com.nageoffer.aicloud.controller;

import com.nageoffer.aicloud.common.convention.result.Result;
import com.nageoffer.aicloud.common.convention.result.Results;
import com.nageoffer.aicloud.dto.req.OpenAIChatReqDTO;
import com.nageoffer.aicloud.dto.req.OpenAIDrawReqDTO;
import com.nageoffer.aicloud.dto.resp.OpenAIChatListRespDTO;
import com.nageoffer.aicloud.dto.resp.OpenAIChatRespDTO;
import com.nageoffer.aicloud.dto.resp.OpenAIDrawListRespDTO;
import com.nageoffer.aicloud.dto.resp.OpenAIDrawRespDTO;
import com.nageoffer.aicloud.service.OpenAiService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ChatGPT对话接口层
 */
@RestController
@RequiredArgsConstructor
public class OpenAIController {
    private final OpenAiService openAiService;

    /**
     * OpenAI对话
     */
    @PostMapping("/api/ai-cloud/v1/openai/chat")
    public Result<OpenAIChatRespDTO> openAiChatQuestion(@RequestBody OpenAIChatReqDTO requestParam,
                                                        @RequestHeader(value = "Authorization", required = false) String authorizationHeader) {
        return Results.success(openAiService.openAiChatQuestion(requestParam));
    }

    /**
     * OpenAI绘图
     */
    @PostMapping("/api/ai-cloud/v1/openai/draw")
    public Result<OpenAIDrawRespDTO> openAiDrawQuestion(@RequestBody OpenAIDrawReqDTO requestParam) {
        return Results.success(openAiService.openAiDrawQuestion(requestParam));
    }

    /**
     * 获取OpenAI历史对话信息
     */
    @PostMapping("/api/ai-cloud/v1/openai/chat-list")
    public Result<List<OpenAIChatListRespDTO>> getOpenAiChatList() {
        return Results.success(openAiService.getOpenAiChatList());
    }

    /**
     * 获取OpenAI历史绘画信息
     */
    @PostMapping("/api/ai-cloud/v1/openai/draw-list")
    public Result<List<OpenAIDrawListRespDTO>> getOpenAiDrawList() {
        return Results.success(openAiService.getOpenAiDrawList());
    }
}
